import {isEmpty} from "@utils";

export default {
  namespaced: true,
  state: {
    keepAlived: [],
    exclude: [],
    refresh: false,
  },
  mutations: {
    addKeepAlive(state: any, componentName: string) {
      if (state.keepAlived.includes(componentName)) return;
      state.keepAlived.push(componentName);
    },
    removeKeepAlive(state: any, componentName: string) {
      if (isEmpty(componentName)) return;
      state.keepAlived = state.keepAlived.filter((k: any) => k != componentName);
      if (!state.exclude.includes(componentName)) {
        state.exclude.push(componentName);
      }
    },
    clearKeepAlive(state: any) {
      // state.keepAlived = [];
      state.exclude = [];
    },
    setReresh(state: any, refresh: boolean) {
      state.refresh = refresh;
    },
  }
}